package com.control.qct.businesssteward.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.adapter.InventoryStatisticAdapter;
import com.control.qct.businesssteward.adapter.InventoryStatisticTableAdapter;
import com.control.qct.businesssteward.base.BaseActivity;
import com.control.qct.businesssteward.model.InventoryStatisticModel;
import com.control.qct.businesssteward.view.CustomCalendarView;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 库存统计
 * Created by Administrator on 2017/12/28 0028.
 */

public class InventoryStatisticActivity extends BaseActivity implements CustomCalendarView.ICallbackClickListener {
    @BindView(R.id.rv_inventory_statistic_table)
    RecyclerView mRvInventoryStatisticTable;
    @BindView(R.id.rv_inventory_statistic)
    RecyclerView mRvInventoryStatistic;
    @BindView(R.id.ccv_date_time)
    CustomCalendarView mCcvDateTime;


    private List<InventoryStatisticModel> mInventoryStatisticModelList;
    private InventoryStatisticTableAdapter mInventoryStatisticTableAdapter;
    private InventoryStatisticAdapter mInventoryStatisticAdapter;
    private int progressMax1;
    private int progressMax2;

    public InventoryStatisticActivity() {
        super(R.layout.activity_inventory_statistic_table);
    }

    @Override
    protected void initView() {
        setLeftIcon(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        setTitle("库存报表");
        setInventoryStatisticBeanList();
        mCcvDateTime.setICallbackClickListener(this);
        mCcvDateTime.setRvCalendarGone(false);
        mRvInventoryStatisticTable.setLayoutManager(new LinearLayoutManager(this));
        mInventoryStatisticTableAdapter = new InventoryStatisticTableAdapter(mInventoryStatisticModelList);
        mRvInventoryStatisticTable.setAdapter(mInventoryStatisticTableAdapter);
        mInventoryStatisticTableAdapter.setProgressMax(progressMax1, progressMax2);
        mRvInventoryStatistic.setLayoutManager(new LinearLayoutManager(this));
        mInventoryStatisticAdapter = new InventoryStatisticAdapter(mInventoryStatisticModelList);
        mRvInventoryStatistic.setAdapter(mInventoryStatisticAdapter);
        mInventoryStatisticAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Bundle bundle = new Bundle();
                bundle.putString("type_name", ((List<InventoryStatisticModel>) adapter.getData()).get(position)
                        .getName());
                startActivity(TypeInventoryStatisticActivity.class, bundle);
            }
        });
    }

    public void setInventoryStatisticBeanList() {
        mInventoryStatisticModelList = new ArrayList<>();
        mInventoryStatisticModelList.add(new InventoryStatisticModel("生鲜水果", 51, 66));
        mInventoryStatisticModelList.add(new InventoryStatisticModel("酒水饮料", 66, 84));
        mInventoryStatisticModelList.add(new InventoryStatisticModel("家用电器", 23, 14));
        mInventoryStatisticModelList.add(new InventoryStatisticModel("服饰鞋包", 22, 23));
        mInventoryStatisticModelList.add(new InventoryStatisticModel("粮油厨房", 67, 50));
        mInventoryStatisticModelList.add(new InventoryStatisticModel("婴幼用品", 88, 33));
        for (int i = 0; i < mInventoryStatisticModelList.size(); i++) {
            if (progressMax1 < mInventoryStatisticModelList.get(i).getNum1()) {
                progressMax1 = mInventoryStatisticModelList.get(i).getNum1() + 10;
            }
            if (progressMax2 < mInventoryStatisticModelList.get(i).getNum2()) {
                progressMax2 = mInventoryStatisticModelList.get(i).getNum2() + 10;
            }
        }
    }

    @Override
    public void leftClick(String time) {
        Log.d("", "leftClick: 执行"+time);
    }

    @Override
    public void rightClick(String time) {
        Log.d("", "rightClick: 执行"+time);
    }

    @Override
    public void itemClick(String time) {

    }
}
